<!--
 * @Description: 
 * @Author: mmzhang
 * @Date: 2022-07-14 11:43:57
 * @LastEditTime: 2022-08-03 16:42:04
-->
<template>
  <dt-modal-edit ref="edit" title="请核对您的调整内容" okText="确认提交" @ok="onOk" :width="900"
    :loading="loading">
    <div class="sub">
      <p class="tips">
        <Icon type="md-alert" :size="20" color="#13227a"
          style="line-height:26px;margin-right:10px;" />请在核对后确认提交。<span
          class="alarm">{{msgTips}}</span>
      </p>
      <dt-info ref="subInfo" :options="subOptions" :info="examineInfo" :label-width="130">
      </dt-info>
    </div>
    <div class="con" v-if="!isSub">
      <p class="tips">
        <Icon type="md-alert" :size="20" color="#13227a"
          style="line-height:26px;margin-right:10px;" />签约总价调整后，将产生相应的正负回款到账记录。<span
          class="alarm">当审核通过后，所有回款将自动入账</span>
      </p>
      <dt-info ref="conInfo" :options="conOptions" :info="examineInfo" :label-width="150">
      </dt-info>
    </div>
    <div class="reason">
      <dt-info ref="reasonInfo" :options="reasonOptions" :info="examineInfo"></dt-info>
    </div>

    <p class="tips">
      <Icon type="md-alert" :size="20" color="#13227a"
        style="line-height:26px;margin-right:10px;" />注意：提交审核时，至少需提供图片附件或文件附件中的1项，否则将无法提交审核</p>

    <div class="file">
      <dt-info ref="fileInfo" :options="fileOptions" :info="examineInfo"></dt-info>
    </div>
  </dt-modal-edit>
</template>
<script>
  import ExamineOpt from './examine'
  import adjustMgr from '@/biz/sales/adjustOrder'
  import dt from '@dt/dt'
  export default {
    data() {
      return {
        isSub: false,
        msgTips: '',
        subOptions: [],
        conOptions: [],
        reasonOptions: [],
        fileOptions: [],
        examineInfo: {
          housesId: dt.buildInfo().housesId,
          adjustmentReason: '',
          imageAnnexes: [],
          fileAnnexes: []
        },
        loading: false,
        adjustmentId: null
      }
    },
    methods: {
      async show(isSub, adjustmentId) {
        this.isSub = isSub
        this.adjustmentId = adjustmentId

        this.examineInfo = {
          housesId: dt.buildInfo().housesId,
          adjustmentReason: '',
          imageAnnexes: [],
          fileAnnexes: []
        }

        if (this.isSub) {
          this.msgTips = '注意：您所调整的认购面积或总价，将在审核通过后生效'
        } else {
          this.msgTips = '注意：您所调整的签约面积或总价，将在审核通过后生效'
          this.conOptions = new ExamineOpt(this).options().conOptions
        }
        await this.getAdjustmentInfo()
        this.examineInfo.housesId = dt.buildInfo().housesId
        this.subOptions = new ExamineOpt(this).options().subOptions
        this.reasonOptions = new ExamineOpt(this).options().reasonOptions
        this.fileOptions = new ExamineOpt(this).options().fileOptions
        this.$refs.edit.show()
      },
      getAdjustmentInfo() {
        let params = {
          adjustmentId: this.adjustmentId
        }
        return adjustMgr.toAdjustmentFun(params).then(res => {
          this.examineInfo = { ...this.examineInfo, ...res }
        }).catch(err => {})
      },
      onOk() {
        if (this.examineInfo.adjustmentReason == '' || this.examineInfo.adjustmentReason ==
          null) {
          this.$Message.error('调整原因不能为空')
          return false
        }
        // 图片和文件必传一项
        if (!(this.examineInfo.fileAnnexes.length || this.examineInfo.imageAnnexes
            .length)) {
          this.$Message.error('图片附件和文件附件必传一项')
          return false
        }

        let params = { ...this.examineInfo }

        this.loading = true
        adjustMgr.submitAdjustmentFun(params).then(res => {
          this.loading = false
          this.$Message.success('操作成功')
          this.$refs.edit.hide()
          this.closeFun()
        }).catch(err => {
          this.loading = false
        })
      },
      closeFun() {
        this.$store.commit('deleteroutefun', this.$route.meta.title)
        setTimeout(() => {
          this.$router.push({
            name: this.isSub ? 'subScriptionAdjust' : 'contractAdjust',
          })
        }, 50)
      }
    }
  }
</script>
<style lang="scss" scoped>
  .tips {
    margin-bottom: 20px;
    background-color: rgba(254, 252, 236, 1);
    line-height: 35px;

    .alarm {
      color: #D9001B;
    }
  }

  .sub,
  .con,
  .reason {
    margin-bottom: 20px;
  }
</style>